package com.dynamixsoftware.printershare.smb;

import com.dynamixsoftware.printershare.smb.util.Dumper;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class SigningDigest
  implements SmbConstants
{
  private boolean bypass = false;
  private MessageDigest digest;
  private byte[] macSigningKey;
  private int signSequence;
  
  SigningDigest(byte[] paramArrayOfByte, boolean paramBoolean)
    throws SmbException
  {
    try
    {
      this.digest = MessageDigest.getInstance("MD5");
      this.macSigningKey = paramArrayOfByte;
      this.bypass = paramBoolean;
      this.signSequence = 0;
      return;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new SmbException("MD5", localNoSuchAlgorithmException);
    }
  }
  
  private byte[] digest()
  {
    return this.digest.digest();
  }
  
  private void update(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    if (paramInt2 == 0) {
      return;
    }
    this.digest.update(paramArrayOfByte, paramInt1, paramInt2);
  }
  
  /* Error */
  void sign(byte[] paramArrayOfByte, int paramInt1, int paramInt2, ServerMessageBlock paramServerMessageBlock1, ServerMessageBlock paramServerMessageBlock2)
  {
    // Byte code:
    //   0: aload 4
    //   2: aload_0
    //   3: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   6: putfield 58	com/dynamixsoftware/printershare/smb/ServerMessageBlock:signSeq	I
    //   9: aload 5
    //   11: ifnull +20 -> 31
    //   14: aload 5
    //   16: iconst_1
    //   17: aload_0
    //   18: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   21: iadd
    //   22: putfield 58	com/dynamixsoftware/printershare/smb/ServerMessageBlock:signSeq	I
    //   25: aload 5
    //   27: iconst_0
    //   28: putfield 61	com/dynamixsoftware/printershare/smb/ServerMessageBlock:verifyFailed	Z
    //   31: aload_0
    //   32: aload_0
    //   33: getfield 37	com/dynamixsoftware/printershare/smb/SigningDigest:macSigningKey	[B
    //   36: iconst_0
    //   37: aload_0
    //   38: getfield 37	com/dynamixsoftware/printershare/smb/SigningDigest:macSigningKey	[B
    //   41: arraylength
    //   42: invokespecial 62	com/dynamixsoftware/printershare/smb/SigningDigest:update	([BII)V
    //   45: iload_2
    //   46: bipush 14
    //   48: iadd
    //   49: istore 9
    //   51: iconst_0
    //   52: istore 10
    //   54: iload 10
    //   56: bipush 8
    //   58: if_icmpge +17 -> 75
    //   61: aload_1
    //   62: iload 9
    //   64: iload 10
    //   66: iadd
    //   67: iconst_0
    //   68: bastore
    //   69: iinc 10 1
    //   72: goto -18 -> 54
    //   75: aload_0
    //   76: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   79: i2l
    //   80: aload_1
    //   81: iload 9
    //   83: invokestatic 66	com/dynamixsoftware/printershare/smb/ServerMessageBlock:writeInt4	(J[BI)V
    //   86: aload_0
    //   87: aload_1
    //   88: iload_2
    //   89: iload_3
    //   90: invokespecial 62	com/dynamixsoftware/printershare/smb/SigningDigest:update	([BII)V
    //   93: aload_0
    //   94: invokespecial 67	com/dynamixsoftware/printershare/smb/SigningDigest:digest	()[B
    //   97: iconst_0
    //   98: aload_1
    //   99: iload 9
    //   101: bipush 8
    //   103: invokestatic 73	java/lang/System:arraycopy	(Ljava/lang/Object;ILjava/lang/Object;II)V
    //   106: aload_0
    //   107: getfield 25	com/dynamixsoftware/printershare/smb/SigningDigest:bypass	Z
    //   110: ifeq +22 -> 132
    //   113: aload_0
    //   114: iconst_0
    //   115: putfield 25	com/dynamixsoftware/printershare/smb/SigningDigest:bypass	Z
    //   118: ldc 75
    //   120: invokevirtual 80	java/lang/String:getBytes	()[B
    //   123: iconst_0
    //   124: aload_1
    //   125: iload 9
    //   127: bipush 8
    //   129: invokestatic 73	java/lang/System:arraycopy	(Ljava/lang/Object;ILjava/lang/Object;II)V
    //   132: aload_0
    //   133: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   136: istore 7
    //   138: aload_0
    //   139: iload 7
    //   141: iconst_2
    //   142: iadd
    //   143: putfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   146: return
    //   147: astore 8
    //   149: aload_0
    //   150: iconst_2
    //   151: aload_0
    //   152: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   155: iadd
    //   156: putfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   159: aload 8
    //   161: athrow
    //   162: astore 6
    //   164: aload_0
    //   165: getfield 39	com/dynamixsoftware/printershare/smb/SigningDigest:signSequence	I
    //   168: istore 7
    //   170: goto -32 -> 138
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	173	0	this	SigningDigest
    //   0	173	1	paramArrayOfByte	byte[]
    //   0	173	2	paramInt1	int
    //   0	173	3	paramInt2	int
    //   0	173	4	paramServerMessageBlock1	ServerMessageBlock
    //   0	173	5	paramServerMessageBlock2	ServerMessageBlock
    //   162	1	6	localException	java.lang.Exception
    //   136	33	7	i	int
    //   147	13	8	localObject	Object
    //   49	77	9	j	int
    //   52	18	10	k	int
    // Exception table:
    //   from	to	target	type
    //   31	45	147	finally
    //   61	69	147	finally
    //   75	132	147	finally
    //   31	45	162	java/lang/Exception
    //   61	69	162	java/lang/Exception
    //   75	132	162	java/lang/Exception
  }
  
  public String toString()
  {
    return "LM_COMPATIBILITY=3 MacSigningKey=" + Dumper.toHexString(this.macSigningKey, 0, this.macSigningKey.length);
  }
  
  boolean verify(byte[] paramArrayOfByte, int paramInt, ServerMessageBlock paramServerMessageBlock)
  {
    update(this.macSigningKey, 0, this.macSigningKey.length);
    update(paramArrayOfByte, paramInt, 14);
    int i = paramInt + 14;
    byte[] arrayOfByte1 = new byte[8];
    ServerMessageBlock.writeInt4(paramServerMessageBlock.signSeq, arrayOfByte1, 0);
    update(arrayOfByte1, 0, arrayOfByte1.length);
    int j = i + 8;
    byte[] arrayOfByte2;
    if (paramServerMessageBlock.command == 46)
    {
      SmbComReadAndXResponse localSmbComReadAndXResponse = (SmbComReadAndXResponse)paramServerMessageBlock;
      update(paramArrayOfByte, j, -8 + (-14 + (paramServerMessageBlock.length - localSmbComReadAndXResponse.dataLength)));
      update(localSmbComReadAndXResponse.b, localSmbComReadAndXResponse.off, localSmbComReadAndXResponse.dataLength);
      arrayOfByte2 = digest();
    }
    for (int k = 0;; k++)
    {
      if (k >= 8) {
        break label185;
      }
      if (arrayOfByte2[k] != paramArrayOfByte[(k + (paramInt + 14))])
      {
        paramServerMessageBlock.verifyFailed = true;
        return true;
        update(paramArrayOfByte, j, -8 + (-14 + paramServerMessageBlock.length));
        break;
      }
    }
    label185:
    paramServerMessageBlock.verifyFailed = false;
    return false;
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.SigningDigest
 * JD-Core Version:    0.7.0.1
 */